package com.epam.debrecen.hackathon.ai.model;

import java.util.ArrayList;
import java.util.List;

public class Region {

	// unique
	private String name;

	private final List<Region> neighbours;

	private String owner;

	private boolean isUnderSiege;

	private boolean isBishopProtected;

	public Region() {
		this(null);
	}

	public Region(String name) {
		this.name = name;
		this.neighbours = new ArrayList<Region>();
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void addNeighbour(Region region) {
		this.neighbours.add(region);
	}

	public List<Region> getNeighbours() {
		return this.neighbours;
	}

	public String getOwner() {
		return this.owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}

	public boolean isUnderSiege() {
		return this.isUnderSiege;
	}

	public void setUnderSiege(boolean isUnderSiege) {
		this.isUnderSiege = isUnderSiege;
	}

	public boolean isBishopProtected() {
		return this.isBishopProtected;
	}

	public void setBishopProtected(boolean isBishopProtected) {
		this.isBishopProtected = isBishopProtected;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("[");
		if (this.neighbours != null && !this.neighbours.isEmpty()) {
			for (int i = 0; i < this.neighbours.size(); i++) {
				sb.append(this.neighbours.get(i).getName() + (i == this.neighbours.size() - 1 ? "" : ", "));
			}
		}
		sb.append("]");

		return "Region [name=" + this.name + ", neighbours=" + sb.toString() + ", owner=" + this.owner + "]";
	}

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Region) {
            Region other = (Region) obj;
            if (this.getName().equals(other.getName())) {
                return true;
            }
        }
        return false;
    }
	
}
